
package fileby.ctrl.actions.impl;

import fileby.model.IMagicBoxManager;
import fileby.util.FileUtil;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 *
 * @author Jacob
 */
class LoadPluginAction extends AbstractAction {

    private IMagicBoxManager magicBoxManager;

    public LoadPluginAction(IMagicBoxManager magicBoxManager) {

        super("Load Plugin", null);
        this.magicBoxManager = magicBoxManager;
        putValue(SHORT_DESCRIPTION, "Load a new plugin");
    }

    public void actionPerformed(ActionEvent e) {
        JFileChooser chooser = new JFileChooser();
        chooser.setMultiSelectionEnabled(false);
        chooser.setDialogTitle("Choose a plugin");
        chooser.setFileFilter(FileUtil.getClassFileFilter());
        chooser.setAcceptAllFileFilterUsed(false);
        int returnValue = chooser.showOpenDialog((JFrame)this.getValue("Parent"));
        if (returnValue == JFileChooser.APPROVE_OPTION)
            magicBoxManager.setNewPlugin(chooser.getSelectedFile());
    }

}
